
package com.huatie.springbootrabbitmq.controller;

import com.huatie.springbootrabbitmq.model.Message;
import com.huatie.springbootrabbitmq.service.RabbitMQProducer;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/api/messages")
public class MessageController {

    @Autowired
    private RabbitMQProducer producer;

    @PostMapping("/send")
    public String sendMessage(@RequestBody Message message) {
        producer.sendMessage(message);
        return "Message sent to RabbitMQ: " + message.getContent();
    }
}
